#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using GameVuTru.ManagerScreens;
using GameVuTru.GameObject;
using GameVuTru.ResourceManager;
#endregion
namespace GameVuTru.Screens
{
    class OptionsMenuScreen : GameScreen
    {
        #region Initialization

        Vector2 posbtnBack = new Vector2(675, 435);
        Vector2 posbtnSquare = new Vector2(230, 167);
        Vector2 postCheckAutoShoot = new Vector2(230, 227);

        public static bool autoshoot = true;
        public OptionsMenuScreen()
        {
            TransitionOnTime = TimeSpan.FromSeconds(0.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);
            EnabledGestures = GestureType.Tap |
                        GestureType.HorizontalDrag |
                        GestureType.Flick |
                        GestureType.Hold |
                        GestureType.VerticalDrag |
                        GestureType.FreeDrag;
        }

        #endregion

        #region Handle Input
        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
            SpriteBatch sp = ScreenManager.SpriteBatch;

            sp.Begin();
            sp.Draw(ReSouce.OptionScreen, Vector2.Zero, Color.White);
            sp.Draw(ReSouce.backButton, posbtnBack, Color.White);
            sp.Draw(ReSouce.Squarebutton, posbtnSquare, Color.White);
            sp.Draw(ReSouce.Squarebutton, postCheckAutoShoot, Color.White);
            if (ManagerSound.soundOn)
            {
                sp.Draw(ReSouce.Checkbutton, new Vector2(posbtnSquare.X + 5, posbtnSquare.Y + 5), Color.White);
            }
            if (autoshoot)
            {
                sp.Draw(ReSouce.Checkbutton, new Vector2(postCheckAutoShoot.X + 5, postCheckAutoShoot.Y + 5), Color.White);
            }
            sp.End();
        }
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

        }
        public override void HandleInput(InputState input)
        {
            base.HandleInput(input);

            foreach (GestureSample item in input.Gestures)
            {
                if (item.GestureType == GestureType.Tap)
                {
                    Point Tap = new Point((int)item.Position.X, (int)item.Position.Y);
                    if (new Rectangle((int)posbtnBack.X, (int)posbtnBack.Y, ReSouce.backButton.Width, ReSouce.backButton.Height).Contains(Tap))
                    {
                        if (ManagerSound.soundOn)
                        {
                            ManagerSound.PlaySound(ReSouce.soundTap);
                        }
                        ScreenManager.RemoveScreen(this);
                        ScreenManager.AddScreen(new MainMenuScreen(), null);
                    }
                    //check play sound
                    if (new Rectangle((int)posbtnSquare.X, (int)posbtnSquare.Y, ReSouce.Squarebutton.Width, ReSouce.Squarebutton.Height).Contains(Tap))
                    {
                        if (ManagerSound.soundOn)
                        {
                            ManagerSound.PlaySound(ReSouce.soundTap);
                        }
                        if (ManagerSound.soundOn)
                        {
                            ManagerSound.soundOn = false;
                            ManagerSound.StopSong();
                        }
                        else
                        {
                            ManagerSound.soundOn = true;
                            ManagerSound.PlaySong(ReSouce.soundMenu);
                        }
                    }

                    //check auto shoot
                    if (new Rectangle((int)postCheckAutoShoot.X, (int)postCheckAutoShoot.Y, ReSouce.Squarebutton.Width, ReSouce.Squarebutton.Height).Contains(Tap))
                    {
                        if (ManagerSound.soundOn)
                        {
                            ManagerSound.PlaySound(ReSouce.soundTap);
                        }
                        if (autoshoot)
                        {
                            autoshoot = false;
                        }
                        else
                        {
                            autoshoot = true;
                        }
                    }
                }
            }
        }

        #endregion
    }
}
